import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import {resolve} from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    plugins: [vue(),
        legacy({
            targets: ['ie >= 11'],
            additionalLegacyPolyfills: ['regenerator-runtime/runtime']
        })],
    resolve: {
        alias: [
            {find: '@', replacement: resolve(__dirname, 'src')},
            {find: /^~/, replacement: ''},
        ],
        extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.mjs']
    },
    optimizeDeps: {
        include: [
            'bpmn-js/lib/Modeler',
        ]
    },
    css: {
        loaderOptions: {
            sass: {
                // 配置全局样式变量
            }
        },
        preprocessorOptions: {
            less: {
                javascriptEnabled: true
            }
        }
    },
    server: {
        host: true,
        cors: true,
        proxy: {
            '/api': {
                target: `http://localhost:8510`,
                //target: `https://n6892t6315.zicp.fun`,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    },
    build: {
        rollupOptions: {
            input: {
                index: resolve(__dirname, 'silly-admin-ui.html'),
            },
            output: {
                chunkFileNames: 'webjars/js/[name]-[hash].js',
                entryFileNames: 'webjars/js/[name]-[hash].js',
                assetFileNames: 'webjars/[ext]/[name]-[hash].[ext]'
            }
        }
    },
})
